package com.sharemedia.utils
{
	import com.sharemedia.vos.Track;
	import com.sharemedia.vos.TrackInfoPacket;
	import com.sharemedia.vos.TrackPacket;
	import com.sharemedia.vos.TrackPrompt;

	public class ConvertUtil
	{
		public static function toTrackPacket(obj:Object):TrackPacket
		{
			var packet:TrackPacket = new TrackPacket(obj.senderPeer, obj.trackUid, obj.broadcastUid, obj.position, obj.bytes, obj.sendTime)
			if(obj.info)
				packet.info = new TrackInfoPacket(obj.info.name, obj.info.artist, obj.info.rating, obj.info.length);
			
			if(obj.prompt)
			{
				var prompt:Array = [];
				for each (var pobj:Object in obj.prompt) 
				{
					prompt.push(new TrackPrompt(pobj.uid, pobj.name, pobj.artist, pobj.rating, pobj.votes))
				}
				
				packet.prompt = prompt;
			}
			
			return packet;
		}
		
		public static function toTrackPrompt(obj:Track):TrackPrompt
		{
			var prompt:TrackPrompt = new TrackPrompt(obj.uid, obj.info.name, obj.info.artist, obj.rating, 0)
			
			return prompt;
		}
	}
}